package com.audaque.springboot.foshanupload.web.webdemo.controller;

import com.audaque.springboot.foshanupload.core.config.ThreadConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("stack")
public class StackController {


    @RequestMapping("listNested")
    public void listNested() {
        List<Object> l = new ArrayList<>();
        l.add(l);
        System.out.println(l.hashCode());
    }


    @RequestMapping("methodNested")
    public void methodNested() {
        Thread.setDefaultUncaughtExceptionHandler(ThreadConfig.threadUncaughtExceptionHandlerImpl());
        //StackOverflowError栈溢出：线程结束，内存被回收，不会影响其他线程
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                test();
            }
        });

        //不受影响
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                //打断点依然可以进来
                System.out.println(i);
            }
        });
        t1.start();
        t2.start();
    }


    public static void test() {
        test();
    }

}
